<?php
/*
 * @Author: your name
 * @Date: 2020-05-09 12:22:09
 * @LastEditTime: 2020-12-28 09:54:58
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /php/application/common/service/LogClientOperation.php
 */
namespace app\common\service\platform_manage\log;

use think\Db;

class LogClientOperationService
{
    /**
     * @name: 获取列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-09 12:23:15
     */
    public function getList ($filter)
    {
        $field = 'lco.*, h.name as host_name, sam.module_name';

        $db = Db::name('LogClientOperation')->alias('lco')
            ->join('Host h', 'h.id=lco.host_id')
            ->join('ServerAuthModule sam', 'lco.module=sam.module_key')
            ->field($field);

        //条件筛选
        if(isset($filter['host_name']) && !empty($filter['host_name']) ){

            $db->where('h.name', 'like', '%'.$filter['host_name'].'%');
        }
        if(isset($filter['event_level']) && !empty($filter['event_level']) ){
            $db->where('lco.event_level', 'like', '%'.$filter['event_level'].'%');
        }
        if(isset($filter['module_name']) && !empty($filter['module_name']) ){
            $db->where('sam.module_name', 'like', '%'.$filter['module_name'].'%');
        }
        if(isset($filter['add_time']) && !empty($filter['add_time']) ){
            $timeStart = strtotime($filter['add_time']);
            $db->whereBetween('lco.add_time', [$timeStart, $timeStart + 86399]);
        }

        $return = $db->paginate()->toArray();

        return $return;
    }
}